package com.yf1706.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yf1706.bean.Emp;
import com.yf1706.service.EmpService;
import com.yf1706.tools.JsonTool;

@Controller
@RequestMapping("emplogin")
public class EmpLoginController extends BaseController{
	
	@Autowired
	private EmpService empService;
	
	@RequestMapping("login")
	public String login() {
		return "djt/EmpLogin";
	}

	@RequestMapping("landing")
	@ResponseBody
	public void landing(HttpServletRequest request,HttpServletResponse response) {
		String Empname = request.getParameter("Empname");
		String password = request.getParameter("Password");
		//去掉员工编号的S  s00001->00001
		Empname = Empname.substring(1);
		JsonTool jTool = new JsonTool();
		try {
			Emp emp = empService.empLogin(Integer.parseInt(Empname), password);
			if (emp != null) {
				HttpSession session=request.getSession();
				session.setAttribute("empUser", emp);
				jTool.setSuccess(true);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		writeJson(jTool, response);
	}
	
	@RequestMapping("emphome")
	public String empHome() {
		return "djt/empHome";
	}
}
